unit Con_Representante;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Db, DbTables, Formulario_Padrao_Consulta, Grids, DBGrids, StdCtrls,
  Buttons, ExtCtrls, TFlatButtonUnit, Provider, DBClient;

type
  TFrmCon_Representante = class(TFrmConsulta)
    Label1: TLabel;
    edtNome: TEdit;
    dbgRepresentante: TDBGrid;
    btnGravar: TFlatButton;
    cdsConsultaRepresentante: TClientDataSet;
    dspConsultaRepresentante: TDataSetProvider;
    dsConsultaRepresentante: TDataSource;
    tq: TQuery;
    procedure BtnFecharClick(Sender: TObject);
    procedure edtNomeKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure FormActivate(Sender: TObject);
    procedure btnGravarClick(Sender: TObject);
    procedure dbgRepresentanteTitleClick(Column: TColumn);

  private
    { Private declarations }
    procedure FazConsulta;

  public
    { Public declarations }
    Rep_Codigo: string;

  end;

var
  FrmCon_Representante: TFrmCon_Representante;

implementation
uses Dm, Biblio, clsRepresentante, Cad_Representante, menu;

{$R *.DFM}

var
  Representante: TRepresentante;

procedure TFrmCon_Representante.BtnFecharClick(Sender: TObject);
begin
  inherited;
  Rep_codigo := cdsConsultaRepresentante.fieldbyname('Rep_Codigo').asstring;

end;

procedure TfrmCon_Representante.FazConsulta;
begin
  if edtnome.text = '' then
    edtnome.text := ' ';
  Representante := TRepresentante.Create;
  TQ.Close;
  cdsConsultaRepresentante.CloSe;
  Representante.Consultar(tq, edtnome.text);

  tq.open;
  cdsConsultaRepresentante.Open;
  Representante.free;
  dbgRepresentante.Refresh;
end;

procedure TFrmCon_Representante.edtNomeKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  inherited;
  if key = 12 then begin
    FazConsulta;
    edtNome.setfocus;
  end;
end;

procedure TFrmCon_Representante.FormActivate(Sender: TObject);
begin
  inherited;
  if FileExists(caminho_personal + 'belquimica') then begin
    btnGravar.Visible := False;
  end;

  tq.databasename := dmint.db.databasename;
  tq.active := False;
  fazconsulta;
  edtnome.setfocus;
end;

procedure TFrmCon_Representante.btnGravarClick(Sender: TObject);
var
  f1: TfrmCad_Representante;
begin
  inherited;
  f1 := TfrmCad_Representante.Create(self);
  f1.btnC_Representante.visible := False;
  f1.ShowModal;
  f1.Free;
  FazConsulta;
end;

procedure TFrmCon_Representante.dbgRepresentanteTitleClick(
  Column: TColumn);
var
  idColSel: Integer;

begin
  inherited;
  cdsConsultaRepresentante.IndexFieldNames := Column.FieldName;

end;

end.
